package com.bdqn.BookManage.dao.impl;

import com.bdqn.BookManage.dao.OrderDao;
import com.bdqn.BookManage.po.Order;
import com.bdqn.BookManage.util.DBUtil;

import java.sql.SQLException;
import java.util.List;

/**
 * @author : CP
 * @version: 1.0
 * @program : BookManage
 * @description : 订单接口实现类
 * @date : 2020-07-31 14:14
 **/
public class OrderDaoImpl implements OrderDao {

    /**
     * 新增订单信息
     * @param order
     * @return
     */
    @Override
    public boolean add(Order order) {
        String sql = "insert into `order` values(null,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        Object [] obj = {order.getOrderNo(),order.getOrderStatus(),order.getTotalMoney(),order.getIsPay(),
        order.getUserAddress(),order.getOrderScore(),order.getOrderRemarks(),order.getCreateTime(),order.getIsClosed(),
        order.getOrderFlag(),order.getTradeNo(),order.getPayFrom(),order.getSettlementId(),order.getRealTotalMoney(),
        order.getReceiveTime(),order.getDeliveryTime()};
        return DBUtil.connZsg(sql,obj);
    }

    /**
     * 根据订单编号查询订单信息
     * @param no 订单编号
     * @return
     */
    @Override
    public Order queryByNo(String no) {
        Order order = null;
        String sql = "select * from `order` where orderNo = ?";
        Object [] obj = {no};
        List<Order> orderList = (List<Order>) DBUtil.queryAll(sql, obj, Order.class);
        if(orderList.size() >0){
            order = orderList.get(0);
        }
        return order;
    }

    /**
     * 修改订单信息
     * @param order 订单信息
     * @return
     */
    @Override
    public boolean amend(Order order) {
        String sql = "update `order` set orderStatus=?,totalMoney=?,isPay=?,userAddress=?,orderScore=?," +
                "orderRemarks=?,createTime=?,isClosed=?,orderFlag=?,tradeNo=?,payFrom=?,settlementId=?," +
                "realTotalMoney=?,receiveTime=?,deliveryTime=? where orderNo=?";
        Object [] obj = {order.getOrderStatus(),order.getTotalMoney(),order.getIsPay(),
                order.getUserAddress(),order.getOrderScore(),order.getOrderRemarks(),order.getCreateTime(),order.getIsClosed(),
                order.getOrderFlag(),order.getTradeNo(),order.getPayFrom(),order.getSettlementId(),order.getRealTotalMoney(),
                order.getReceiveTime(),order.getDeliveryTime(),order.getOrderNo()};
        return DBUtil.connZsg(sql,obj);
    }
}
